package Leetcode;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class Leetcode_235 {
    public static int countMatches(List<List<String>> items, String ruleKey, String ruleValue) {
        int index = new HashMap<String, Integer>() {{
            put("type", 0);
            put("color", 1);
            put("name", 2);
        }}.get(ruleKey);
        int res = 0;
        for (List<String> item : items) {
            if (item.get(index).equals(ruleValue)) {
                res++;
            }
        }
        return res;
    }

    public static void main(String[] args) {
        List<List<String>> items =  new ArrayList<List<String>>();
        List<String> items1 = new ArrayList<String>();
        List<String> items2 = new ArrayList<String>();
        List<String> items3 = new ArrayList<String>();
        items1.add("phone");
        items1.add("blue");
        items1.add("pixel");
        items2.add("computer");
        items2.add("silver");
        items2.add("lenovo");
        items3.add("phone");
        items3.add("gold");
        items3.add("iphone");
        items.add(items1);
        items.add(items2);
        items.add(items3);
        String ruleKey = "type", ruleValue = "phone";
        System.out.println(countMatches(items,ruleKey,ruleValue));
    }
}
